home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr40 / radserv.zip / RADDISP.C < prev    next >
C/C++ Source or Header  |  1995-01-23  |  3KB  |  132 lines

  1.  
  2. /*
  3.  * Sample Code. This routines demonstrates how the satellite parameters
  4.  * received from VersaTrack can be used to update a control in a dialog
  5.  * box. The code is neither elegant nor efficient nor useful. It is just
  6.  * meant as a sample...
  7.  */
  8.  
  9. #include "resource.h"
  10. #include "radextrn.h"
  11. #include "vsttype.h"
  12. #include <math.h>
  13. #include <time.h>
  14.  
  15. extern radparam_t rigInfo;
  16. static char buf[256];
  17.  
  18. struct dupdate {
  19.     int id;
  20.     char *str;
  21. } utab[] = {
  22.     IDC_RDISPLAY_RXFREQ, buf,
  23.     IDC_RDISPLAY_TXFREQ, buf+16,
  24.     IDC_RDISPLAY_RXCENTER, buf+32,
  25.     -1, NULL,
  26. };
  27.  
  28. static void
  29. DChildPos(HWND hwnd, int *xsize, int *ysize)
  30. {
  31.     RECT r;
  32.     int extra_x, extra_y;
  33.  
  34.     extra_x = GetSystemMetrics(SM_CXFRAME) * 2;
  35.     extra_y = GetSystemMetrics(SM_CYFRAME) * 2 +
  36.               GetSystemMetrics(SM_CYCAPTION) +
  37.               GetSystemMetrics(SM_CYMENU); /* Optional */
  38.     
  39.     GetClientRect(hwnd, &r);
  40.     *xsize = r.right  + extra_x;
  41.     *ysize = r.bottom + extra_y;
  42. }
  43.  
  44.  
  45. fdummy(radparam_t *rp) /* needed because of compiler optimization
  46.     assumes the value does not ever change and loads it into a register... */
  47. {
  48.     return rp->radio.ra_doppler;
  49. }
  50.  
  51. void
  52. rdisp_update()
  53. {
  54.     radioinfo_t *rp;
  55.     int f, ghz, mhz, khz, d;
  56.     extern HWND rdhwnd;
  57.  
  58.     if (!rdhwnd)
  59.         return;
  60.         
  61.     rp = &rigInfo.radio;
  62.     fdummy(&rigInfo);
  63.     if (buf[32] == 0) {
  64.         ghz = rp->ra_rxcenter / 1000000;
  65.         mhz = rp->ra_rxcenter / 1000;
  66.         khz = (rp->ra_rxcenter - (mhz * 1000)) * 1000;
  67.         sprintf(buf+32, "%02d.%03d.%06d", ghz, mhz, khz); /* rx center */
  68.     }
  69.     d = rp->ra_doppler / 1000;
  70.     f = rp->ra_rxcenter + d;
  71.     d = rp->ra_doppler - (d * 1000);
  72.     fdummy(&rigInfo);
  73.     ghz = f / 1000000;
  74.     mhz = f / 1000;
  75.     khz = (f - (mhz * 1000)) * 1000 + d;
  76.     sprintf(buf+ 0, "%02d.%03d.%06d", ghz, mhz, khz);
  77.     fdummy(&rigInfo);
  78.     ghz = rp->ra_txcenter / 1000000;
  79.     mhz = rp->ra_txcenter / 1000;
  80.     khz = (rp->ra_txcenter - (mhz * 1000) ) * 1000;
  81.     sprintf(buf+ 16, "%02d.%03d.%06d", ghz, mhz, khz);
  82.  
  83.     PostMessage(rdhwnd, WM_USER+1, (WPARAM) 0, (LPARAM) buf);
  84. }
  85.  
  86. BOOL CALLBACK
  87. RadioDisplay(hwnd, message, wParam, lParam)
  88. HWND hwnd;
  89. UINT message;
  90. WPARAM wParam;
  91. LPARAM lParam;
  92. {
  93.     int cmd, xs, ys;
  94.     extern HWND rdhwnd;
  95.     struct dupdate *dp;
  96.  
  97.     if (message == WM_MOUSEMOVE)
  98.         return TRUE;
  99.             
  100.     switch(message) {
  101.         case WM_INITDIALOG:
  102.             DChildPos(hwnd, &xs, &ys);
  103.             /* Adjust the size of parent so we'll fill its main window area */
  104.             SetWindowPos(hwnd, 0, 0, 0, 0, 0,
  105.                 SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
  106.             SetWindowPos(Gwnd, 0, 0, 0, xs, ys,
  107.                 SWP_NOMOVE | SWP_NOZORDER | SWP_SHOWWINDOW);
  108.             rdisp_update();                
  109.             return TRUE;
  110.  
  111.         case WM_COMMAND:
  112.             cmd = LOWORD(wParam);
  113.             break;
  114.  
  115.         case WM_CLOSE:
  116.             DestroyWindow(hwnd);
  117.             rdhwnd = NULL;
  118.             return TRUE;
  119.  
  120.         case WM_USER+1:            
  121.             for (dp = utab; dp->str; dp++)
  122.                 SendDlgItemMessage(hwnd, dp->id, WM_SETTEXT, (WPARAM)0,
  123.                     (LPARAM) dp->str);
  124.             break;
  125.         default:
  126.             break;
  127.     }
  128.     return FALSE;
  129. }
  130.  
  131.        
  132.